#ifndef SHAREDLIBRARY_H_INCLUDED
#define SHAREDLIBRARY_H_INCLUDED

#include <Ape/Object.h>
#include <Ape/IO/FS/FSObject.h>

namespace Ape {
	class String;
	namespace IO {
		namespace FS {
			class Path;
		}
	}
	
	namespace Ext {
		using Ape::IO::FS::Path;
		using Ape::IO::FS::FSObject;
		
		class SharedLibrary : public FSObject {
			TYPE_NAME ("Ape::Ext::SharedLibrary")
		public:
			typedef void* Handle_t;
		private:
			Handle_t m_Handle;
			
			static String GetActivatorNameForClass (const String& className);
		public:
			SharedLibrary (const Path& path);
			virtual ~SharedLibrary();
			void Open();
			void Close();
			
			void* Resolve (const String& symName);
			
			template <typename Data_t>
			Data_t ResolveTyped (const String& symName) {
				return reinterpret_cast<Data_t> (Resolve (symName) );
			}
			
			Ape::Object* Activate (const String& className);
			template <class Data_t>
			Data_t* ActivateTyped (const String& symName) {
				return dynamic_cast<Data_t*> (Activate (symName) );
			}
			
			void DisposeObject (Ape::Object* obj);
		};
	}
}

#endif // SHAREDLIBRARY_H_INCLUDED
